package com.example.mvvmdemo.activity.litepal;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;

import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;

import com.example.mvvmdemo.R;
import com.example.mvvmdemo.database.litepal.Actor;
import com.example.mvvmdemo.database.litepal.Comment;
import com.example.mvvmdemo.database.litepal.Movie;
import com.example.mvvmdemo.databinding.ActivityDataLitepalBinding;
import com.example.mvvmdemo.databinding.ActivityMainBinding;

import org.litepal.tablemanager.Connector;

public class DataLitepalActivity extends AppCompatActivity {
    private SQLiteDatabase db;
    private ActivityDataLitepalBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_data_litepal);
        binding.setLifecycleOwner(this);
        binding.setHandler(this);
        initViewModel();
        initView();
    }

    private void initViewModel(){

    }

    private void initView(){
        db = Connector.getDatabase();
        Log.d("TAG", String.valueOf(db.isOpen()));
    }

    public void insertData(){
        Movie movie1 = new Movie();
        movie1.setName("封神:朝歌风云");
        movie1.setYear("2023");
        Movie movie2 = new Movie();
        movie2.setName("蜘蛛侠:纵横宇宙");
        movie2.setYear("2020");
        Movie movie3 = new Movie();
        movie3.setName("保你平安");
        movie3.setYear("2022");

        Actor actor1 = new Actor();
        actor1.setName("周星驰");
        actor1.setAge(28);
        actor1.setSex("男");
        Actor actor2 = new Actor();
        actor2.setName("吴孟达");
        actor2.setAge(36);
        actor2.setSex("男");
        Actor actor3 = new Actor();
        actor3.setName("娜然");
        actor3.setAge(18);
        actor3.setSex("女");
        Actor actor4 = new Actor();
        actor4.setName("郭富城");
        actor4.setAge(40);
        actor4.setSex("男");

        Comment comment1 = new Comment();
        comment1.setComment("不错");
        Comment comment2 = new Comment();
        comment2.setComment("太好看了");
        Comment comment3 = new Comment();
        comment3.setComment("烂片");
        Comment comment4 = new Comment();
        comment4.setComment("一般般");
        Comment comment5 = new Comment();
        comment5.setComment("太好看了,爽片");
        Comment comment6 = new Comment();
        comment6.setComment("一般般");
        Comment comment7 = new Comment();
        comment7.setComment("还行");
        Comment comment8 = new Comment();
        comment8.setComment("史上最佳");

        movie1.getActorList().add(actor1);
        movie1.getActorList().add(actor3);
        movie1.getActorList().add(actor4);
        movie2.getActorList().add(actor1);
        movie2.getActorList().add(actor2);
        movie2.getActorList().add(actor4);
        movie3.getActorList().add(actor2);
        movie3.getActorList().add(actor4);
        movie1.getCommentList().add(comment1);
        movie1.getCommentList().add(comment2);
        movie1.getCommentList().add(comment4);
        movie2.getCommentList().add(comment3);
        movie2.getCommentList().add(comment8);
        movie3.getCommentList().add(comment6);
        movie3.getCommentList().add(comment7);
        movie3.getCommentList().add(comment5);

        movie1.save();
        movie2.save();
        movie3.save();
        actor1.save();
        actor2.save();
        actor3.save();
        actor4.save();
        comment1.save();
        comment2.save();
        comment3.save();
        comment4.save();
        comment5.save();
        comment6.save();
        comment7.save();
        comment8.save();
    }
    public void deleteData(){

    }
    public void updateData(){

    }
    public void queryData(){

    }
}